package logic

import (
	"context"
	"ewaimai/waimairpc/internal/svc"
	"ewaimai/waimairpc/models"
	"ewaimai/waimairpc/waimairpc"
	"github.com/zeromicro/go-zero/core/logx"
)

type ShopListLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShopListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShopListLogic {
	return &ShopListLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShopListLogic) ShopList(in *waimairpc.ShopListRequest) (*waimairpc.ShopListResponse, error) {
	// todo: add your logic here and delete this line

	var g []models.Goods

	models.DB.Debug().Order("price desc").Find(&g)
	var shoplist []*waimairpc.ShopList
	for _, goods := range g {
		list := waimairpc.ShopList{
			Name:   goods.Name,
			Price:  float32(goods.Price),
			Num:    int64(goods.Num),
			Status: 1,
			UserId: int64(goods.UserId),
		}
		shoplist = append(shoplist, &list)
	}
	return &waimairpc.ShopListResponse{
		List: shoplist,
	}, nil
}
